package com.ericom.webapp.action;

import java.util.List;

import com.ericom.model.ReturnGoodsOrder;
import com.ericom.service.GenericManager;

public class ReturnGoodsOrderAction extends BaseAction{
	private GenericManager<ReturnGoodsOrder, Long> returnGoodsOrderManager;
	private List returnGoodsOrders;
	private ReturnGoodsOrder returnGoodsOrder;
	private Long id;

	public ReturnGoodsOrder getReturnGoodsOrder() {
		return returnGoodsOrder;
	}

	public void setReturnGoodsOrder(ReturnGoodsOrder returnGoodsOrder) {
		this.returnGoodsOrder = returnGoodsOrder;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setReturnGoodsOrderManager(
			GenericManager<ReturnGoodsOrder, Long> returnGoodsOrderManager) {
		this.returnGoodsOrderManager = returnGoodsOrderManager;
	}

	public String list() {
		returnGoodsOrders = returnGoodsOrderManager.getAll();
		return SUCCESS;
	}

	public List getReturnGoodsOrders() {
		return returnGoodsOrders;
	}

	public String delete() {
		returnGoodsOrderManager.remove(returnGoodsOrder.getId());
		this.saveMessage(getText("returnGoodsOrder.deleted"));
		return this.SUCCESS;
	}

	public String edit() {
		if (id != null) {
			returnGoodsOrder = returnGoodsOrderManager.get(id);
		} else {
			returnGoodsOrder = new ReturnGoodsOrder();
		}
		return this.SUCCESS;
	}

	public String save() throws Exception {
		if (this.cancel != null) {
			return this.CANCEL;
		}
		if (this.delete != null) {
			return this.delete();
		}

		boolean isNew = (returnGoodsOrder.getId() == null);

		returnGoodsOrder = returnGoodsOrderManager.save(returnGoodsOrder);

		String key = (isNew) ? "returnGoodsOrder.added"
				: "returnGoodsOrder.updated";
		this.saveMessage(getText(key));

		if (!isNew) {
			return this.INPUT;
		} else {
			return this.SUCCESS;
		}
	}
}
